package creational.property.reigister;

public class Test {

    public static void main(String[] args) {
        HondaCar pHondaCar1 = new HondaCar();
        pHondaCar1.setName("honda1");
        CarPropertyManager.getInstance().setProperty("honda", pHondaCar1);

        HondaCar pCopyHondaCar1 = (HondaCar) CarPropertyManager.getInstance().getProperty("honda");
        System.out.println("本田1原型：" + pHondaCar1.toString());
        System.out.println("本田1克隆：" + pCopyHondaCar1.toString());
        System.out.println("本田1和本田1克隆是否为同一个对象：" + (pCopyHondaCar1 == pHondaCar1));

        HondaCar pHondaCar2 = new HondaCar();
        pHondaCar2.setName("honda2");
        CarPropertyManager.getInstance().setProperty("honda", pHondaCar2);
        HondaCar pCopyHondaCar2 = (HondaCar) CarPropertyManager.getInstance().getProperty("honda");
        System.out.println("本田1原型：" + pHondaCar1.toString());
        System.out.println("本田2克隆：" + pCopyHondaCar2.toString());
        System.out.println("本田1和其本田2克隆是否为同一个对象：" + (pCopyHondaCar2 == pHondaCar1));

        //这里添加了新的原型
        AudiCar pAudiCar1 = new AudiCar();
        pAudiCar1.setName("Audi1");
        CarPropertyManager.getInstance().setProperty("audi", pAudiCar1);
        AudiCar pCopyAudiCar1 = (AudiCar) CarPropertyManager.getInstance().getProperty("audi");
        System.out.println("奥迪1原型：" + pAudiCar1.toString());
        System.out.println("奥迪1克隆：" + pCopyAudiCar1.toString());
        System.out.println("奥迪1原型和奥迪1克隆是否为同一个对象：" + (pAudiCar1 == pCopyAudiCar1));
        HondaCar pCopyHondaCar3 = (HondaCar) CarPropertyManager.getInstance().getProperty("honda");
        System.out.println("奥迪3原型：" + pCopyHondaCar3.toString());

    }

}
